Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkString fixes (mostly moved from the multi-decl overhaul) #714

Merged
merged 8 commits into from
Oct 6, 2021

Conversation

mattmccutchen-cci
Copy link
Member

Most of these fixes are ones that were previously needed in #657 when it switched all unchanged multi-decl members from Decl::print to mkString, in order to prevent 3C's output from getting worse on some unchanged multi-decl members in the regression tests. The fixes are no longer needed for that reason, but Mike still asked me to submit them. See the commit messages for additional information.

This PR addresses several of the sub-issues of #703.

Back when the multi-decl overhaul
(#657) switched
all unchanged multi-decl members from Decl::print to mkString, these
fixes were needed to prevent 3C's output from getting worse on some
unchanged multi-decl members in the regression tests. The fixes are no
longer needed for that reason, but Mike still asked me to submit them.
They do benefit some more complex cases that occur in the regression
tests, so the updates to the expected output of those tests provide test
coverage for the fixes.
I'm including this because the code fix was similar to a fix that was
originally in the multi-decl overhaul before the same fix was needed in
#702 and I was
aware of the issue from item 4 of
#703.
Copy link
Member

@kyleheadley kyleheadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adds special cases to existing code that improves the regression tests, so great job there. The block comment is out of place and needs to be consistent with the rest of the function.

Simplify the last paragraph and move it to the top of the function because it applies generally.

Convert the rest to 1-3 line comments directly referring to a line of code and place them above it.

General knowledge that you deem important can be moved to issue #703 to assist in the overhaul of the function.

As I dug into the reasons why all the conditionals in the PR so far were
needed under the current design of the rest of mkString, I realized that
the design could be straightened out a bit and correctly handle one more
case involving checked pointers to fixed-size arrays. This doesn't
address the more difficult problems with wild pointers to fixed-size
arrays or with wild pointer levels being in reverse order in general
(see #703).
@mattmccutchen-cci
Copy link
Member Author

After struggling to break down the block comment into smaller pieces (the logic was very interdependent and I couldn't find a way to explain it adequately in 3-line units associated with individual lines of code), I ended up finding a way to simplify the design so that I didn't need such a long comment to explain it. 🙂

Copy link
Collaborator

@john-h-kastner john-h-kastner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are just thoughts on some of the existing mkString code, so feel free to ignore.

clang/lib/3C/ConstraintVariables.cpp Show resolved Hide resolved
clang/lib/3C/ConstraintVariables.cpp Outdated Show resolved Hide resolved
Any array levels still pending when we reach a function pointer should
become part of the function pointer declarator even if some text for an
outer checked pointer level has already been added to Ss. However, any
array levels that are outside the checked pointer level and have already
been committed to EndStrs should remain at the end of the entire type
and not get sucked into the function pointer declarator. To maintain
this distinction, we need to use a separate `FptrEndStrs` list for the
array levels in the function pointer declarator.
Also update a link to go to an existing issue John pointed out.
Copy link
Member Author

@mattmccutchen-cci mattmccutchen-cci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I addressed John's comments, updated an issue link to go to #161 (thanks John), and made a bonus fix related to function pointers.

clang/lib/3C/ConstraintVariables.cpp Outdated Show resolved Hide resolved
clang/lib/3C/ConstraintVariables.cpp Show resolved Hide resolved
Copy link
Member

@kyleheadley kyleheadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were able to refactor and remove some variables. What was the key insight that allowed the change?

clang/lib/3C/ConstraintVariables.cpp Show resolved Hide resolved
Copy link
Member Author

@mattmccutchen-cci mattmccutchen-cci left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You were able to refactor and remove some variables. What was the key insight that allowed the change?

I'm assuming we're focusing on this commit; I think each of the other comments is reasonably easy to understand or sufficiently documented by itself.

Here's as much of my thought process as I can reconstruct: After I traced through the execution of the code on the various examples described in the original comment, I realized that the reason I originally needed a special case for function pointers was so that the array levels would be transferred from ConstArrs to EndStrs in time for the if (FV) code block. There was already a conditional addArrayAnnotations call near there, and if I made it unconditional, I probably wouldn't need function pointers to do the addArrayAnnotations where I originally added it. So I looked at what else broke when I made that change, and I found out that the name ended up before the array levels in some cases. Swapping the order of emission of the name and the EndStrs was sufficient to fix that. The rest of the commit was mostly a matter of simplifying conditional expressions and deleting code that I confirmed was no longer needed.

Really, the proof is in the pudding: the regression tests pass, and I've left mkString simpler than I found it. I don't think it's my responsibility in this PR to try to explain or rationalize all of the existing mkString code.

clang/lib/3C/ConstraintVariables.cpp Show resolved Hide resolved
@kyleheadley
Copy link
Member

kyleheadley commented Oct 4, 2021

Here's as much of my thought process as I can reconstruct

Great, now I can understand the refactor as centering around addArrayAnnotations, not about removing the variables even though they show up prominently in the diff.

Really, the proof is in the pudding: the regression tests pass,

I assumed as much, most of the time people remember to check before posting.

I don't think it's my responsibility in this PR to try to explain or rationalize all of the existing mkString code.

That goes without saying. I hope you didn't have a reason to think that it was asked of you.

We do this all the time in our documentation.

But code comments are not documentation, at least, I've never used them as such, except for the blocks before functions that show up in automated tools. Perhaps this is a topic we should discuss as a group.

Copy link
Member

@kyleheadley kyleheadley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactor looks fine. Mike agreed that the comment seemed out of place but in such a long, complex function it doesn't distract much. So I'll let that go and that was everything left holding this PR back for me.

If you think you now understand enough about mkString to leave the longer comment above as Mike suggested, I'd encourage you to do that before merging.

@mattmccutchen-cci
Copy link
Member Author

If you think you now understand enough about mkString to leave the longer comment above as Mike suggested, I'd encourage you to do that before merging.

I improved the comment on ConstraintVariable::mkString a bit based on my current understanding; I hope this is accurate. Does it look OK to you? There are probably other pieces of information that would be worth including there, but I think it's beyond my responsibility to research them for this PR; I tried to find a reasonable compromise on how much work to do in this PR. I don't think we need separate comments for the {Pointer,Function}VariableConstraint::mkString overrides at this point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants